/*
Statusus
v 1.0

Extension for sharing selected text with your Twitter or Facebook friends.

Copyright(c) Adil Aliyev
24 December 2010
E-mail: adil@adil.az
Web: http://adil.az

*/
var context = "selection";

var mainMenu = chrome.contextMenus.create({"title": "Statusus", "contexts":[context]});

function openAdilWindow(url) {
	chrome.windows.create({"url":url,"width":550,"height":350});
}

function openAdilTab(url) {
	chrome.tabs.create({"url":url});
}

function shareOnTwitter(info,tab) {
	if (info.selectionText.length>130) alert("Length of the selected texts is too large. Maximum allowed is 130 symbols. :)");
	else openAdilWindow("http://twitter.com/share?url="+escape(info.pageUrl)+"&via=Statusus&text="+info.selectionText);
}

function shareOnFacebook(info,tab) {
	if (info.selectionText.length>420) alert ("Length of the selected texts is too large. Maximum allowed is 420 symbols. :)");
	else openAdilTab("http://www.facebook.com/dialog/feed?app_id=158809844165673&redirect_uri=http://facebook.com&message="+info.selectionText);
}


var twitterMenu = chrome.contextMenus.create({"title":"Twitter","contexts":[context],"parentId":mainMenu,"onclick":shareOnTwitter});
var facebookMenu = chrome.contextMenus.create({"title":"Facebook","contexts":[context],"parentId":mainMenu,"onclick":shareOnFacebook});
